<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-projInfo-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">证件号码：</label>
				<div class="col-sm-8">
					<input id="empId" name="empId" th:value="${baseInfo.empId}" class="form-control" type="text" readonly="readonly">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">姓名：</label>
				<div class="col-sm-8">
					<input id="empNm" name="empNm" th:value="${baseInfo.empNm}" class="form-control" type="text" readonly="readonly">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">项目名称：</label>
				<div class="col-sm-8">
					<input id="empPjNm" name="empPjNm" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">项目类型：</label>
				<div class="col-sm-8">
					<select id="empPjType" class="form-control m-b" th:with="type=${@dict.getType('pm_pj_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">项目角色：</label>
				<div class="col-sm-8">
					<input id="empPjRole" name="empPjRole" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
					<label class="col-sm-3 control-label">日期：</label>
					<div class="col-sm-8 form-inline select-month">
								<input type="text" class="time-input form-control" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span class="form-control text-center" style="border:0;">至</span>
								<input type="text" class="time-input form-control" id="endTime" placeholder="结束时间" name="params[endTime]"/>
					</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">项目所属公司：</label>
				<div class="col-sm-8">
					<!--<input id="empComp" name="empComp" class="form-control" type="text">-->
					<select id="empComp" name="empComp" class="form-control m-b" th:with="type=${@WorkInfoServiceImpl.getType(baseInfo.empId)}">
						<option th:each="dict : ${type}" th:text="${dict}" th:value="${dict}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">责任描述：</label>
				<div class="col-sm-8">
					<textarea type="text" id="empPjDesc" name="empPjDesc" class="form-control" placeholder="请输入文本"></textarea>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    
    <script type="text/javascript">
		var prefix = ctx + "pm/projInfo";
		// laydate 时间控件绑定
		layui.use('laydate', function() {
		    var laydate = layui.laydate;
		    var startDate = laydate.render({
		        elem: '#startTime',
		        max: $('#endTime').val(),
		        theme: 'default',
		        type: 'month',
		        trigger: 'click',
		        done: function(value, date) {
		            // 结束时间大于开始时间
		            if (value !== '') {
		                endDate.config.min.year = date.year;
		                endDate.config.min.month = date.month - 1;
		                endDate.config.min.date = date.date;
		            } else {
		                endDate.config.min.year = '';
		                endDate.config.min.month = '';
		                endDate.config.min.date = '';
		            }
		        }
		    });
		    var endDate = laydate.render({
		        elem: '#endTime',
		        min: $('#startTime').val(),
		        theme: 'default',
		        type: 'month',
		        trigger: 'click',
		        done: function(value, date) {
		            // 开始时间小于结束时间
		            if (value !== '') {
		                startDate.config.max.year = date.year;
		                startDate.config.max.month = date.month - 1;
		                startDate.config.max.date = date.date;
		            } else {
		                startDate.config.max.year = '';
		                startDate.config.max.month = '';
		                startDate.config.max.date = '';
		            }
		        }
		    });
		});
		
		$("#form-projInfo-add").validate({
			rules:{
                empPjNm:{
					required:true
				},
                empPjType:{
                    required:true
				},
                empPjRole:{
                    required:true
				},
                empPjStdt:{
                    required:true
				},
                empPjEddt:{
                    required:true
				},
                empComp:{
                    required:true
				},
                empPjDesc:{
                    required:true
				}
			}
		});

        function submitHandler() {
            if ($.validate.form()) {
                var result = checkDateOverlap();
                if (result.toString() === "1") {
                    add();
                } else {
                    $.modal.alertError("时间重叠");
                }
            }
        }

        function checkDateOverlap() {
            var flag = "";
            var empPjStdt = $("#startTime").val();
            var empPjEddt = $("#endTime").val();
            var empId = $("input[name='empId']").val();
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "pm/projInfo/checkDate",
                data : {
                    "empId": empId,
                    "startDate": empPjStdt,
                    "endDate": empPjEddt,
                    "operationType": "add"
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("时间重叠");
                },
                success : function(data) {
                    flag = data;
                }
            });
            return flag;
        }
		
		function add() {
			var empId = $("input[name='empId']").val();
        	var empNm = $("input[name='empNm']").val();
        	var empPjNm = $("input[name='empPjNm']").val();
        	var empPjType = $("#empPjType option:selected").val();
        	var empPjRole = $("input[name='empPjRole']").val();
        	var empComp = $("#empComp option:selected").val();
        	var empPjDesc = $("textarea[name='empPjDesc']").val();
        	var empPjStdt = $("#startTime").val();
        	var empPjEddt = $("#endTime").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "pm/projInfo/add",
        		data : {
        			"empId": empId,
        			"empNm": empNm,
        			"empPjNm": empPjNm,
        			"empPjType": empPjType,
        			"empPjRole": empPjRole,
        			"empPjStdt": empPjStdt,
        			"empPjEddt": empPjEddt,
        			"empComp": empComp,
        			"empPjDesc": empPjDesc
        		},
        		async : true,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }
		
	</script>
</body>
</html>
